package leetcode.code1291;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution {
	List<Integer> ans;
	int low, high;

	public List<Integer> sequentialDigits(int low, int high) {
		ans = new ArrayList<>();
		this.low = low;
		this.high = high;
		for (int i = 1; i < 9; i++) {
			this.f(i, i);
		}
		Collections.sort(ans);
		return ans;
	}

	private void f(int cur, int num) {
		if (num > high || cur > 9) {
			return;
		}
		if (num >= low && num <= high) {
			ans.add(num);
		}
		this.f(cur + 1, num * 10 + cur + 1);
	}
}
